﻿using AutoMapper;
using SIG.Model.Identity;
using SIG.Model;
using SIG.Model.Store;
using SIG.ViewModel.Admin.Store;
using SIG.InputModel.Admin.Store;
using SIG.InputModel.Admin.Ads;
using System;
using SIG.Model.Articles;
using SIG.ViewModel.Admin.Articles;
using SIG.InputModel.Admin.Articles;
using SIG.InputModel.Admin;
using SIG.Model.FQAs;
using SIG.ViewModel.Admin.FQAs;
using SIG.InputModel.Admin.FQAs;
using SIG.InputModel.Admin.Links;
using SIG.ViewModel.Admin.Links;
using SIG.ViewModel.Admin.Announcements;
using SIG.Model.Announcements;
using SIG.ViewModel.Admin.Videos;
using SIG.Model.Videos;
using SIG.InputModel.Admin.Announcements;
using SIG.InputModel.Admin.Videos;
using SIG.ViewModel.Admin.Emails;
using SIG.Model.Emails;
using SIG.ViewModel.Admin.Menus;
using SIG.InputModel.Admin.Emails;
using SIG.InputModel.Admin.Identity;
using SIG.ViewModel.Admin.Chronicles;
using SIG.Model.Chronicles;
using SIG.InputModel.Admin.Chronicles;
using SIG.ViewModel.Admin.Albums;
using SIG.InputModel.Admin.Albums;
using SIG.Model.Albums;
using SIG.ViewModel.Admin.Pages;
using SIG.InputModel.Admin.Pages;
using SIG.ViewModel.Admin.Jobs;
using SIG.Model.Jobs;
using SIG.InputModel.Admin.Jobs;
using SIG.Model.Teams;
using SIG.ViewModel.Admin.Teams;
using SIG.InputModel.Admin.Teams;
using SIG.ViewModel.Admin.Identity;
using SIG.Model.Ads;
using SIG.ViewModel.Admin.Ads;
using SIG.InputModel.Admin.Menus;
using SIG.ViewModel.Admin.Case;
using SIG.Model.Case;
using SIG.InputModel.Admin.Case;
using SIG.ViewModel.Admin.Blogs;
using SIG.Model.Blogs;
using SIG.InputModel.Admin.Blogs;
using SIG.ViewModel.Admin.DataAcquisition;
using SIG.Model.DataAcquisition;
using SIG.InputModel.Admin.DataAcquisition;
using SIG.ViewModel.Admin.Menu;
using SIG.InputModel.Admin.Products;
using SIG.ViewModel.Admin.Products;
using SIG.Model.LuceneSearch;
using SIG.InputModel.Admin.LuceneSearch;

namespace SIG.WebMVC.Mappings
{
    public class DomainToViewModelMappingProfile : Profile
    {
        public DomainToViewModelMappingProfile()
        {
            CreateMap<Menu, MenuVM>();
            CreateMap<MenuVM, Menu>();

            CreateMap<Menu, BaseMenuVM>();
            CreateMap<BaseMenuVM, Menu>();

            CreateMap<SIG.DAL.Dapper.Model.Menu, MenuIM>();
            CreateMap<MenuIM, SIG.DAL.Dapper.Model.Menu>();
            CreateMap<SIG.DAL.Dapper.Model.Menu, FrontMenuIM>();
            CreateMap<FrontMenuIM, SIG.DAL.Dapper.Model.Menu>();
            CreateMap<Menu, UserMenuDTO>();

            CreateMap<MenuCategory, MenuCategoryVM>();
            CreateMap<MenuCategoryIM, SIG.DAL.Dapper.Model.MenuCategory>();
            CreateMap<SIG.DAL.Dapper.Model.MenuCategory, MenuCategoryIM>();

            CreateMap<User, ProfileIM>();
            CreateMap<ProfileIM, User>();
            CreateMap<SIG.DAL.Dapper.Model.User, ProfileIM>();
            CreateMap<ProfileIM, SIG.DAL.Dapper.Model.User>();
            CreateMap<User, UserVM>();
            CreateMap<UserVM, User>();

            //Mapper.CreateMap<Diary, DiaryDTO>().ForMember(d=>d.ProjectTitle,opt=>opt.MapFrom(source=>source.Project.Title))
            //    .ForMember(d=>d.WorkTypeTitle, opt=>opt.MapFrom(source=>source.WorkType.Title));

            //Mapper.CreateMap<InAccount, InAccountDTO>().ForMember(d => d.ProjectTitle, opt => opt.MapFrom(source => source.Project.Title))
            //   .ForMember(d => d.InTypeTitle, opt => opt.MapFrom(source => source.InType.Title))
            //   .ForMember(d => d.CustomerName, opt => opt.MapFrom(source => source.Customer.CustomerName));
            CreateMap<CategoryVM, Category>();
            CreateMap<Category, CategoryVM>();
            CreateMap<CategoryIM, SIG.DAL.Dapper.Model.Category>();
            CreateMap<SIG.DAL.Dapper.Model.Category, CategoryIM>();

            CreateMap<SIG.DAL.Dapper.Model.Product, ProductIM>();
            CreateMap<ProductIM, SIG.DAL.Dapper.Model.Product>();
            CreateMap<Product, ProductVM>().ForMember(d => d.PhotoCount, opt => opt.MapFrom(source => source.ProductPhotoes.Count));
            CreateMap<ProductVM, Product>();

            CreateMap<TechnologyIM, SIG.DAL.Dapper.Model.Technology>();
            CreateMap<SIG.DAL.Dapper.Model.Technology, TechnologyIM>();

            CreateMap<Product, SearchData>().ForMember(d => d.Name, opt => opt.MapFrom(source => source.ProductName));


            CreateMap<Article, ArticleVM>().ForMember(d => d.CategoryTitle, opt => opt.MapFrom(source => source.Category.Title));
            CreateMap<SIG.DAL.Dapper.Model.Article, ArticleIM>();
            CreateMap<ArticleIM, SIG.DAL.Dapper.Model.Article>();
            CreateMap<ArticleCategoryVM, ArticleCategory>();
            CreateMap<ArticleCategory, ArticleCategoryVM>();
            CreateMap<ArticleCategoryIM, SIG.DAL.Dapper.Model.ArticleCategory>();
            CreateMap<SIG.DAL.Dapper.Model.ArticleCategory, ArticleCategoryIM>();

            //CreateMap<Page, PagePageMetaDTO>();
            //CreateMap<PagePageMetaDTO, Page>();

            CreateMap<PageMeta, ArticleIM>().ForMember(x => x.Id, opt => opt.MapFrom(source => source.ObjectId));
            CreateMap<ArticleIM, PageMeta>().ForMember(x => x.ObjectId, opt => opt.MapFrom(source => source.Id));

            CreateMap<GoodsCategoryVM, GoodsCategory>();
            CreateMap<GoodsCategory, GoodsCategoryVM>();
            CreateMap<GoodsCategoryIM, GoodsCategory>();
            CreateMap<GoodsCategory, GoodsCategoryIM>();

            CreateMap<Goods, GoodsVM>().ForMember(d => d.CategoryTitle, opt => opt.MapFrom(source => source.GoodsCategory.Title));
            CreateMap<Goods, GoodsIM>();

            CreateMap<GoodsVM, Goods>();
            CreateMap<GoodsIM, Goods>();

            CreateMap<GoodsPhotoVM, GoodsPhoto>();
            CreateMap<GoodsPhotoIM, GoodsPhoto>();
            CreateMap<GoodsPhoto, GoodsPhotoVM>();
            CreateMap<GoodsPhoto, GoodsPhotoIM>();

            CreateMap<SIG.DAL.Dapper.Model.Position, PositionIM>();
            CreateMap<PositionIM, SIG.DAL.Dapper.Model.Position>();
            CreateMap<Position, PositionVM>();
            CreateMap<PositionVM, Position>();
            CreateMap<SIG.DAL.Dapper.Model.Carousel, CarouselIM>();
            CreateMap<CarouselIM, SIG.DAL.Dapper.Model.Carousel>();
            CreateMap<Carousel, CarouselVM>();
            CreateMap<CarouselVM, Carousel>();


            CreateMap<Question, QuestionVM>().ForMember(d => d.CategoryTitle, opt => opt.MapFrom(source => source.Category.Title));
            CreateMap<Question, QuestionVM>();
            CreateMap<QuestionIM, Question>();
            CreateMap<Question, QuestionIM>();
            CreateMap<QuestionCategoryVM, QuestionCategory>();
            CreateMap<QuestionCategory, QuestionCategoryVM>();
            CreateMap<QuestionCategoryIM, QuestionCategory>();
            CreateMap<QuestionCategory, QuestionCategoryIM>();

            CreateMap<LinkCategoryVM, LinkCategory>();
            CreateMap<LinkCategory, LinkCategoryVM>();
            CreateMap<LinkCategoryIM, SIG.DAL.Dapper.Model.LinkCategory>();
            CreateMap<SIG.DAL.Dapper.Model.LinkCategory, LinkCategoryIM>();
            CreateMap<LinkVM, Link>();
            CreateMap<Link, LinkVM>();
            CreateMap<LinkIM, SIG.DAL.Dapper.Model.Link>();
            CreateMap<SIG.DAL.Dapper.Model.Link, LinkIM>();

            CreateMap<AnnouncementVM, Announcement>();
            CreateMap<Announcement, AnnouncementVM>();
            CreateMap<AnnouncementIM, Announcement>();
            CreateMap<Announcement, AnnouncementIM>();

            CreateMap<VideoVM, Video>();
            CreateMap<Video, VideoVM>();
            CreateMap<VideoIM, SIG.DAL.Dapper.Model.Video>();
            CreateMap<SIG.DAL.Dapper.Model.Video, VideoIM>();

            CreateMap<EmailVM, Email>();
            CreateMap<Email, EmailVM>();

            CreateMap<EmailAccountVM, EmailAccount>();
            CreateMap<EmailAccount, EmailAccountVM>();
            CreateMap<EmailAccountIM, SIG.DAL.Dapper.Model.EmailAccount>();
            CreateMap<SIG.DAL.Dapper.Model.EmailAccount, EmailAccountIM>();

            CreateMap<EmailTemplateVM, EmailTemplate>();
            CreateMap<EmailTemplate, EmailTemplateVM>();
            CreateMap<EmailTemplateIM, SIG.DAL.Dapper.Model.EmailTemplate>();
            CreateMap<SIG.DAL.Dapper.Model.EmailTemplate, EmailTemplateIM>();

            CreateMap<ChronicleVM, Chronicle>();
            CreateMap<Chronicle, ChronicleVM>();
            CreateMap<ChronicleIM, Chronicle>();
            CreateMap<Chronicle, ChronicleIM>();

            CreateMap<AlbumVM, Album>();
            CreateMap<Album, AlbumVM>();
            CreateMap<AlbumIM, SIG.DAL.Dapper.Model.Album>();
            CreateMap<SIG.DAL.Dapper.Model.Album, AlbumIM>();

            CreateMap<PhotoVM, Photo>();
            CreateMap<Photo, PhotoVM>();
            CreateMap<PhotoIM, SIG.DAL.Dapper.Model.Photo>();
            CreateMap<SIG.DAL.Dapper.Model.Photo, PhotoIM>();

            CreateMap<PageVM, Page>();
            CreateMap<Page, PageVM>();
            CreateMap<PageIM, SIG.DAL.Dapper.Model.Page>();
            CreateMap<SIG.DAL.Dapper.Model.Page, PageIM>();

            CreateMap<JobVM, Job>();
            CreateMap<Job, JobVM>();
            CreateMap<JobIM, Job>();
            CreateMap<Job, JobIM>();

            CreateMap<TeamVM, Team>();
            CreateMap<Team, TeamVM>();
            CreateMap<TeamIM, SIG.DAL.Dapper.Model.Team>();
            CreateMap<SIG.DAL.Dapper.Model.Team, TeamIM>();

            CreateMap<ClientVM, Client>();
            CreateMap<Client, ClientVM>();
            CreateMap<ClientIM, SIG.DAL.Dapper.Model.Client>();
            CreateMap<SIG.DAL.Dapper.Model.Client, ClientIM>();

            CreateMap<SolutionVM, Solution>();
            CreateMap<Solution, SolutionVM>();
            CreateMap<SolutionIM, Solution>();
            CreateMap<Solution, SolutionIM>();

            CreateMap<WorkTypeVM, WorkType>();
            CreateMap<WorkType, WorkTypeVM>();
            CreateMap<WorkCategoryIM, SIG.DAL.Dapper.Model.WorkCategory>();
            CreateMap<SIG.DAL.Dapper.Model.WorkCategory, WorkCategoryIM>();

            CreateMap<WorkVM, Work>();
            CreateMap<Work, WorkVM>();
            CreateMap<WorkIM, SIG.DAL.Dapper.Model.Work>();
            CreateMap<SIG.DAL.Dapper.Model.Work, WorkIM>();

            CreateMap<PostCategoryVM, PostCategory>();
            CreateMap<PostCategory, PostCategoryVM>();
            CreateMap<PostCategoryIM,SIG.DAL.Dapper.Model.PostCategory>();
            CreateMap<SIG.DAL.Dapper.Model.PostCategory, PostCategoryIM>();

            CreateMap<PostVM, Post>();
            CreateMap<Post, PostVM>();
            CreateMap<PostIM, SIG.DAL.Dapper.Model.Post>();
            CreateMap<SIG.DAL.Dapper.Model.Post, PostIM>();

            CreateMap<FilterTemplateVM, FilterTemplate>();
            CreateMap<FilterTemplate, FilterTemplateVM>();
            CreateMap<FilterTemplateIM, FilterTemplate>();
            CreateMap<FilterTemplate, FilterTemplateIM>();

            CreateMap<SearchData, SearchDataIM>();
            CreateMap<SearchDataIM, SearchData>();

            //Mapper.CreateMap<Goal, GoalListViewModel>().ForMember(x => x.SupportsCount, opt => opt.MapFrom(source => source.Supports.Count))
            //                                          .ForMember(x => x.UserName, opt => opt.MapFrom(source => source.User.UserName))
            //                                          .ForMember(x => x.StartDate, opt => opt.MapFrom(source => source.StartDate.ToString("dd MMM yyyy")))
            //                                          .ForMember(x => x.EndDate, opt => opt.MapFrom(source => source.EndDate.ToString("dd MMM yyyy")));
            //Mapper.CreateMap<Group, GroupsItemViewModel>().ForMember(x => x.CreatedDate, opt => opt.MapFrom(source => source.CreatedDate.ToString("dd MMM yyyy")));

            //Mapper.CreateMap<IPagedList<Group>, IPagedList<GroupsItemViewModel>>().ConvertUsing<PagedListConverter<Group, GroupsItemViewModel>>();


        }
    }
}